﻿

// 简单生产者代码（用于测试）
using RabbitMQ.Client;
using System.Text;

var factory = new ConnectionFactory 
{
    HostName = "localhost",
    Port = 5672,
    UserName = "guest",
    Password = "guest"
};
using var connection = await factory.CreateConnectionAsync();
using var channel = await connection.CreateChannelAsync();
await channel.QueueDeclareAsync("hello", false, false, false, null);


while (true)
{
    Console.WriteLine("请输入消息:");
    string? msg = Console.ReadLine();

    if(string.IsNullOrEmpty(msg))
    {
        Console.WriteLine("不能输入空消息");
        continue;
    }

    var body = Encoding.UTF8.GetBytes(msg);
    await channel.BasicPublishAsync(
    exchange: "",          // 默认交换器（direct）
    routingKey: "Hello",   // 路由键 = 队列名（使用默认交换器时）
    body: new ReadOnlyMemory<byte>(body)
);

}